Don't get excited and try and create tables or anything cool like that with the HTMLToRichText(&Buffer) Perm.
void dbReleaseMe(DB box) {
hide(box)
destroy(box);
}
RTF_string__ richTextOfHtml(string htmlText) {
Buffer b = create();
b = htmlText;
//--------------------------------------------------------------------------
// NOTE: b is an in/out parameter. Upon call, HTML text is read from the
// input buffer. Upon function completion, the same buffer's content
// will be replaced with rich text that corresponds to the HTML
// supplied as input. The string return value may contain an
// error message if the conversion is unsuccessful (I have only gotten
// empty strings in my experiments).
//--------------------------------------------------------------------------
string errorMsg = HTMLToRichText(b);
// Never got one ...
if (length(errorMsg) > 0) {
ack("Error during HTMLToRichText(): " errorMsg);
halt;
}
RTF_string__ richTextString = richText(stringOf(b));
string richTextString1 = stringOf(b);
delete b;
b = null;
return richTextString;
}
string plainTextOfHtml(string htmlText) {
Buffer b = create();
b = htmlText;
string errorMsg = HTMLToRichText(b);
if (length(errorMsg) > 0) {
ack("Error during HTMLToRichText(): " errorMsg);
halt;
}
string plainText = plainText(stringOf(b));
delete(b);
b = null();
return plainText;
}
// Empirically derived (no science here)
int richSize(string plainString) {
real len = realOf(length(plainString));
real width = len * 0.82;
return (intOf(width));
}
void htmlTagsSupportedByDxl() {
string htmlString;
htmlString = "Normal" //-
" <b>bold</b>" //-
" <i>italic</i>" //-
" <u>underlined</u> " //-
" <s>strike</s> " //-
" <sup>superscript</sup> " //-
" <sub>subscript</sub>" //-
" back to normal";
DB box = centered("HTML tags supported by HTMLToRichText");
bool readOnly = true;
DBE field1 = richField(box, //-
" Original: ", //-
richText(htmlString), //-
richSize(htmlString), //-
readOnly );
DBE field3 = richField(box, //-
" Plain: ", //-
richText(plainTextOfHtml(htmlString)), //-
richSize(htmlString), //-
readOnly );
DBE field2 = richField(box, //-
"Converted: ", //-
richTextOfHtml(htmlString), //-
richSize(htmlString), //-
readOnly );
close(box, false, dbReleaseMe);
show(box)
}
htmlTagsSupportedByDxl();
SystemAdmin - Thu Dec 22 12:49:40 EST 2011 |